html
<template>
	<view class="code">
		<view class="code-title">
			<view class="code-img" @click="scanCode">
				<image
					src="https://heda123.oss-cn-guangzhou.aliyuncs.com/upload/3/20250218/ae8bc09dff45cb7a7fe918cc81e58ef8.png"
					mode=""></image>
			</view>
			<form class="form-box" @submit="handleExchange">
				<view class="input-container">
					<input v-model="inputValue" name="inputValue" class="input-box" placeholder="请输入兑换码进行兑换" />
					<button form-type="submit" class="exchange-button">兑换</button>
				</view>
			</form>
		</view>

		<view class="code-content">
			<view class="tabs">
				<view v-for="(tab, index) in tabs" :key="index" class="tab" :class="{'active': currentTab === index}"
					@click="changeTab(index)">
					{{ tab }}
				</view>
				<view class="tabs-btn" @click="open">
					兑换规则
				</view>
			</view>
			<view class="tabs-content" v-if="currentTab == 0">
				<nodata></nodata>
			</view>
			<view class="tabs-content" v-if="currentTab == 1">
				<nodata></nodata>
			</view>
		</view>
		<uni-popup ref="notice" class="pop" type="center">
			<view class="popup-box">
				<view class="popup-title">
					兑换规则
				</view>
				<view class="popup-content">
					<view class="popup-text ">
						兑换说明
					</view>
					<view class="popup-rule">
						1.兑换码为一串数字字母的组合
					</view>
					<view class="popup-rule">
						2.兑换成功后可在"我的优惠券"中查看
					</view>
					<view class="popup-rule text-red">
						3.优惠券存在有效期，逾期自动失效，不补发，不延期，请及时兑换
					</view>
					<view class="popup-text ">
						使用说明
					</view>
					<view class="popup-rule">
						1.兑换码仅限兑换优惠券，不可兑换现金/找零
					</view>
					<view class="popup-rule">
						2.同一兑换码仅限兑换一张优惠券，成功兑换后将失效，不可重复兑换
					</view>
					<view class="popup-rule ">
						3.优惠券具体使用规则请以优惠券详情为准
					</view>
				</view>
				<view class="popup-btn" @click="close">
					<text class="popup-close">我已知晓</text>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputValue: '',
				currentTab: 0,
				tabs: ['待使用', '不可用'],
			};
		},
		methods: {
			changeTab(index) {
				this.currentTab = index;
			},
			open() {
				this.$refs.notice.open()
			},
			close(){
				this.$refs.notice.close()
			},
			scanCode() {
				uni.scanCode({
					success: (res) => {
						console.log('扫码成功，返回结果:', res);
						uni.showToast({
							title: '扫描成功: ' + res.result,
							icon: 'none'
						});
					},
					fail: (err) => {
						console.error('扫码失败:', err);
						uni.showToast({
							title: '扫码失败，请重试',
							icon: 'none'
						});
					}
				});
			},
			handleExchange(event) {
				// 直接获取输入框的值
				const inputValue = this.inputValue.trim();

				if (inputValue) {
					uni.showToast({
						title: `兑换码: ${inputValue}`,
						icon: 'success',
					});
					// 处理兑换码逻辑
					console.log('兑换码:', inputValue);
				} else {
					uni.showToast({
						title: '请输入有效的兑换码',
						icon: 'none',
					});
				}
			},
		},
	};
</script>

<style>
	.code {
		padding: 20rpx;
	}

	.code-title {
		display: flex;
		align-items: center;
	}

	.code-img {
		width: 80rpx;
		height: 80rpx;
	}

	.code-img image {
		width: 100%;
		height: 100%;
	}

	.form-box {
		width: 85%;
	}

	.input-container {
		display: flex;
		align-items: center;
		position: relative;
		width: 100%;
		margin-left: 20rpx;
	}

	.input-box {
		flex: 1;
		height: 60rpx;
		border: 1px solid #ccc;
		padding: 0 20rpx;
		border-radius: 30rpx;
		font-size: 28rpx;
		box-sizing: border-box;
	}

	.exchange-button {
		position: absolute;
		right: 0;
		height: 60rpx;
		line-height: 60rpx;
		background-color: #d81e06;
		color: #fff;
		border-radius: 30rpx;
		font-size: 28rpx;
		padding: 0 30rpx;
		z-index: 999;
	}

	.code-content {
		background-color: #fff;
		margin-top: 20rpx;
		padding: 20rpx;
	}

	.tabs {
		display: flex;
		align-items: center;
		position: relative;
	}

	.tabs-btn {
		position: absolute;
		right: -20rpx;
		background-color: #d1d1d1;
		color: #fff;
		padding: 10rpx 20rpx;
		font-size: 24rpx;
		border-radius: 6rpx;
		text-align: center;
	}

	.tab {
		padding: 20rpx;
		border-bottom: 2px solid transparent;
		color: #897;
	}

	.tab.active {
		border-bottom: 2px solid #000;
		color: #000;
		font-weight: 700;
	}

	.tab-content {
		margin-top: 20px;
	}

	.tab-item {
		padding: 20px;
		background-color: #f5f5f5;
		border-radius: 8px;
	}

	.uni-popup__wrapper-box {
		background-color: #fff;

	}

	.popup-box {
		background-color: #fff;
		position: relative;
		padding: 20rpx;
		width: 80vw;
	}

	.popup-title {
		padding: 20rpx;
		text-align: center;
		font-weight: 600;
		color: #666;
	}


	.popup-fw {
		font-size: 38rpx;
		font-weight: 600;
	}

	.popup-text {
		color: #666;
		font-size: 24rpx;
		margin: 20rpx 0;
	}

	.popup-rule {
		margin: 10rpx 0;
		color: #666;
		font-size: 24rpx;
	}

	.text-red {
		color: #fe1d38;
	}
	.popup-btn{
		text-align: center;
		margin-top: 40rpx;
		
	}
	.popup-close{
		padding:10rpx 20rpx;
		background-color: #f0f0f0;
		border-radius: 10rpx;
	}
</style>